-- thump
-- create by dengc
-- 技能: 重击

return {
    apply = function(source, target, skillId, round, para, extra)
        local curHp = target:queryAttrib("hp");
        local maxHp = target:getMaxHp();

        local hpBoundary = para[1];
        local multiple = para[2];

        -- 增加命中动作
        SkillM.initSequence(source, target, skillId);
        SkillM.getSequence(target):remoteAttack(source, target, skillId);

        -- 生命千分比低于一定值，那么斩杀目标，否则造成N倍伤害
        local permillage = FormulaM.invoke("CALC_BIG_DIVISION", curHp, 1000, maxHp);
        local damage;
        if permillage < hpBoundary then
            -- 加上护盾值的伤害
            damage = target:getHp();

            -- 造成直接伤害
            CombatM.doDamage(source, target, damage, skillId);
        else
            damage = source:getAttack();
            damage = FormulaM.invoke("CALC_BIG_DIVISION", damage, multiple, 1000);
            -- 承受伤害
            CombatM.receiveDamage(source, target, damage, skillId);
        end
        
        -- 清空能量
        local amount = source.dbase:query("energy", 0);
        source.dbase:set("energy", 0);
        EventMgr.fire(event.COST_ENERGY, {
            ["amount"]  = amount,
            ["pos"]     = source:getPos(),
            ["attrib"]  = "energy",
        });

    end,

    parse = function(desc)
        local arr = string.explode(desc, ",");
        return { tonumber(arr[1]), tonumber(arr[2]), };
    end,

    -- 解析技能描述
    parseDesc = function(source, skillId, desc, para)
        return desc;
    end,
}

